import segmentation from '/public/configuration'
import axios from 'axios'
let base = segmentation.uploadPictures


const baseAxios = axios.create({
    baseURL: base,
    withCredentials: false,
    timeout: 100000000
})
// 添加请求拦截器
// let signData = funs(JSON.stringify(data)).toUpperCase();
baseAxios.interceptors.request.use(
    config => {
        config.headers['appKey'] = 'nsfocus-aeoi-det'
        config.headers['appSecret'] = 'bnNmb2N1cy1hZW9pLWRldC1ibk5tYjJOMWN5MWhaVzlwTFdSbGRBPT0='
        config.headers['Access-Control-Allow-Origin'] = '*'
        config.headers.Authorization = sessionStorage.getItem('token')
        config.headers['Access-Control-Allow-Credentials'] = true
        config.headers['Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild'];
        return config
    },
    // store.state.isspinning  ?   store.state.spinning = true : '',
    function (error) {
        // 对请求错误做些什么
        // Store.commit('setOverall', false)
        return Promise.reject(error)
    }
)
// 添加响应拦截器
baseAxios.interceptors.response.use(
    response => {

        sessionStorage.setItem('token', response.headers.authorization)

        if (response.data.code == 2 || response.data.code == 3) {
            //console.log('访问出错401001')
            alert(response.data.msg)
            // Modal.Delete(responseFun, response.data.msg, responseFun)
            return
        } else if (response.data.code == 500) {
            alert(response.data.msg)
        }else if (response.data.code == 15) {
            alert(response.data.msg)
            // alert(response.data.msg)
        }

        // function responseFun() {
        //     sessionStorage.clear();
        //     window.location.href = "/";
        // }
        // if (response.status === 200) {
        //     if (response.status === 200) {
        //         return response.data
        //     } else {
        //         return false
        //     }
        // } else {
        //     //alert('网络异常!请稍后再试')
        // }


        // eslint-disable-next-line no-undef
        // store.state.spinning = false
        return response.data
        // eslint-disable-next-line no-undef
    }, error => {

        setTimeout(() => {
            // this.Hint({
            //     message: '出错了，稍后刷新重试一下',
            //     type: 'warning'
            // });
        }, 500)
        return Promise.reject(error);
    }
)

export default baseAxios
